﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEditor;
using UnityEngine;

public class MyEditor : Editor
{
    [MenuItem("GameObject/UI/Scroll View Ex(Horizontal) #&a", false, 1)]
    static void aa()
    {
        Debug.Log(11111111);
    }

    [MenuItem("Tool/恢复快捷键", false, 1)]
    static void ResetHotKeyMain()
    {
        ResetHotKey();
        ResetHotKey1();
    }
    static void ResetHotKey()
    {
        string sTestFileName = @"H:\git\github\testUGUI\Assets\Editor\MyEditor.cs";
        sTestFileName = Path.Combine(Application.dataPath, "Editor\\MyEditor.cs");
        string str = File.ReadAllText(sTestFileName);
        string aa = @"//[MenuItem(""GameObject/UI/Scroll View Ex(Horizontal) #&a"", false, 1)]";
        string bb = @"[MenuItem(""GameObject/UI/Scroll View Ex(Horizontal) #&a"", false, 1)]";
        bool flag = true;

        if (str.IndexOf(aa) == -1)
        {
            //Console.WriteLine("没找到恢复的标志");
            flag = false;
        }
        if (flag == true)
        {
            File.WriteAllText(sTestFileName, File.ReadAllText(sTestFileName).Replace(aa, bb), Encoding.UTF8);
            //AssetDatabase.Refresh();
            Debug.Log("恢复成功");
            return;
        }


        flag = true;
        if (str.IndexOf(bb) == -1)
        {
            //Console.WriteLine("没找到");
            flag = false;
        }
        if (flag == true)
        {
            File.WriteAllText(sTestFileName, File.ReadAllText(sTestFileName).Replace(bb, aa), Encoding.UTF8);
            //AssetDatabase.Refresh();
            Debug.Log("替换成功");
        }
    }
    static void ResetHotKey1()
    {
        string sTestFileName = @"H:\git\github\testUGUI\Assets\Editor\MyEditor2.cs";
        sTestFileName = Path.Combine(Application.dataPath, "Editor\\MyEditor2.cs");

        string str = File.ReadAllText(sTestFileName);
        string aa = "//本次修改仅为方便本地开发，不可提交仓库！！！\n//本次修改仅为方便本地开发，不可提交仓库！！！\n//本次修改仅为方便本地开发，不可提交仓库！！！\n/*\n";
        string bb = "";
        bool flag = true;

        if (str.IndexOf(aa) == -1)
        {
            //Console.WriteLine("没找到恢复的标志");
            flag = false;
        }
        if (flag == true)
        {
            File.WriteAllText(sTestFileName, File.ReadAllText(sTestFileName).Replace(aa, bb), Encoding.UTF8);
            File.WriteAllText(sTestFileName, File.ReadAllText(sTestFileName).Replace("*/", ""), Encoding.UTF8);
            //AssetDatabase.Refresh();
            Debug.Log("恢复成功");
            return;
        }

        File.WriteAllText(sTestFileName, aa + str + "*/", Encoding.UTF8);
        Debug.Log("替换成功");
    }
}